package cn.doit.scala.day03

import cn.doit.scala.day03.beans.User

/**
 * @DATE 2021/12/27/15:06
 * @Author MDK
 * @Version 2021.2.2
 * */
object C07_GroupBy02 {
  def main(args: Array[String]): Unit = {
    val users = List[User](User(1,"ly",23),User(2,"zss",17),User(3,"wss",34),User(4,"wql",34))
    //按照年龄分组的两种方法  Comparable比较

    val mp = users.groupBy(user => user.age)
    var i = 0
    mp.foreach(tp=>{
      i+=1
      println(s"这是第${i}组数据")
      val groupName = tp._1
      val list: List[User] = tp._2
      for (elem <- list) {
        println(groupName+"-"+elem.name)
      }
    })
  }
}
